#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

void ShowImage(Mat &mat);
void WriteImage(const string &path, Mat &mat);
int main()
{
    string srcPath = "/Users/huyaohua/yangxu/workspace/QRCodeDetectorDemo/srcImage/img14.jpg";
    string dstPath = "/Users/huyaohua/yangxu/workspace/QRCodeDetectorDemo/dstImage/img14.jpg";

    Mat srcImage = imread(srcPath);

    cvtColor(srcImage, srcImage, COLOR_BGR2GRAY);
    adaptiveThreshold(srcImage, srcImage, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 55, 8);

    ShowImage(srcImage);
    WriteImage(dstPath, srcImage);

    waitKey();
    return 0;
}

void ShowImage(Mat &mat) {
    int nRows = 500;
    int nCols =mat.cols*nRows / mat.rows;
    Size size = Size(nCols, nRows);
    Mat tmp;
    resize(mat, tmp, size);
    imshow("picture", tmp);
}

void WriteImage(const string &path, Mat &mat) {
    const Mat &tmp = mat;
    imwrite(path.c_str(), tmp);
}

